--[[ 编码: WMS-19-06 名称: 容器货品明细-删除后 作者:HAN 日期:2025-1-29 级别:固定 (说明本段代码在项目中不太会变化) 函数: AfterDataObjDelete 功能: -- 减【容器货品】中的相关货品的数量如果为0 需要删除这个记录 -- 如果有上架单需要扣除【上架单明细】这里的累计绑定数量 -- 调用 wms_Putaway_DecAccBindingQty 容器货品解绑操作,并减上架单绑定数量 更改记录: --]] wms_base = require( "wms_base" ) function AfterDataObjDelete ( strLuaDEID ) local nRet, strRetInfo -- step1: 获取当前【容器货品明细】对象 local cg_detail nRet, cg_detail = m3.GetSysCurEditDataObj( strLuaDEID, "CG_Detail" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..cg_detail ) end if ( cg_detail.item_merge == 'Y') then local cg_id = cg_detail.cg_id local qty = cg_detail.qty if ( cg_id == '' ) then -- 这种情况是系统检测 CG_Detail 中的 S_CG_ID 已经无效后设置为空后产生的 lua.Warning( strLuaDEID, debug.getinfo(1), "CG_Detail 中的S_CG_ID为空! " ) return end -- step2: 获取【容器货品】对象中的数量如果 <= 就删除 local strCondition = "S_ID = '"..cg_id.."'" nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr( strLuaDEID, "Container_Good", strCondition, "F_QTY" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取条件'"..strCondition.."'的【容器货品】属性失败! "..id ) end if ( strRetInfo == '' ) then return end local cg_attrs = json.decode( strRetInfo ) local cg_qty = lua.StrToNumber( cg_attrs[1].value ) if ( cg_qty > qty ) then local strSetSQL = "F_QTY = F_QTY - " ..qty nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Container_Good", strCondition, strSetSQL) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "设置条件'"..strCondition.."'的【容器货品】数量失败!"..strRetInfo) end else nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "Container_Good", strCondition) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除【容器货品】失败!"..strRetInfo) end end end -- step3: 容器货品解绑操作 if (cg_detail.bs_no ~= '') then -- V10.0 local strCondition if ( cg_detail.bs_type == "Inbound_Order") then -- 业务来源是 入库单 strCondition = "S_IO_NO = '"..cg_detail.bs_no.."' AND N_ROW_NO = "..cg_detail.bs_row_no nRet, strRetInfo = mobox.decDataObjAccQty( strLuaDEID, "Inbound_Detail", strCondition, "F_ACC_B_QTY", cg_detail.qty) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "decDataObjAccQty(Inbound_Detail)失败! "..strRetInfo ) end end end -- V9.1 容器中的 N_DETAIL_COUNT - 1 local strCondition = "S_CODE = '"..cg_detail.cntr_code.."'" local strUpdateSql = "N_DETAIL_COUNT = N_DETAIL_COUNT - 1" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Container", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【容器】中的明细条数失败!"..strRetInfo ) end end